﻿// See https://aka.ms/new-console-template for more information
using FreeSql;
using FreeSql.Internal;
using System.Data.Common;
using System.Data;
using XuguClient;

namespace Xugu_demo;
class Program {
    private static readonly IFreeSql fsql;
    /// <summary>
    /// 请修改，需要创建一个模式 
    /// CodeFirst方式
    /// </summary>
    private static readonly string connStr = "IP=127.0.0.1;DB=SYSTEM;User=SYSDBA;PWD=SYSDBA;Port=5138;AUTO_COMMIT=on;CHAR_SET=UTF8";

    /// <summary>
    /// 获取ORM freesql  
    /// </summary>
    static Program()
    {
        var dbBuilder = new FreeSqlBuilder();
        var conn = new XGConnection(connStr);

        fsql = dbBuilder
            .UseConnectionString(DataType.Xugu, connStr)
               //.UseConnectionFactory(DataType.Xugu, () => conn)
               .UseNameConvert(NameConvertType.ToUpper)
               .UseAutoSyncStructure(true) //CodeFirst 自动同步实体类结构，生成数据库表
               .UseNoneCommandParameter(true)
               .UseMonitorCommand(cmd =>
               {
                   //AOP拦截输出要提交给数据库驱动的SQL语句
                   Console.WriteLine($"提交的SQL语句：{cmd.CommandText};");
               })
               .Build(); 

    }
    private static void Main(string[] args)
    {
        try
        {
            var res = fsql.Insert<ConferenceTest>(new ConferenceTest
            {
                Participants = "TTTTTTTTTEST",
                Title = "测试数据",
                DataTime = DateTime.Now.AddDays(1),
                StartTime = DateTime.Now,
                EndTime = DateTime.Now.AddHours(10),
            }).ExecuteIdentity();
            Console.WriteLine(res);

        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message); 
        }
        Console.ReadLine();

    }
}

